import * as Draw from './draw.js';

// 约定参数
const radius = 10;
// 
const pic = 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1531214138209&di=9bdab820f972680b8845217c61b894d4&imgtype=jpg&src=http%3A%2F%2Fimg4.imgtn.bdimg.com%2Fit%2Fu%3D325440579%2C2874869038%26fm%3D214%26gp%3D0.jpg';

// const pic = "https://static.newyali.com/yaliapi/0/article/11d8e201807061032189778.jpg?imageView2/0/w/1080/h/255";
// 文字绘制器
export const textPainter = {
  paint: function (sprite, cxt) {
    Draw.save_return(cxt, () => {
      cxt.beginPath();
      cxt.setFontSize(40);
      Draw.drawText(sprite.text, sprite.left, sprite.top, sprite.width, cxt, sprite.lineheight ? sprite.lineheight : 20 )
    })
  }
}
// 矩形绘制器
export const rectPainter = {
  paint: function (sprite, cxt) {
    
  }
}
// 圆角图片绘制器
export const picPainter = {
  paint: function (sprite, cxt) {
    
    const rect = Draw.Rect(sprite.left, sprite.top, sprite.width, sprite.height);
    
    const doDraw = () => {
      console.log(123);
      Draw.drawUsingArc(rect, radius, cxt);
      cxt.fillStyle = '#fff';
      cxt.fill();
      cxt.clip();
      // cxt.rect(100, 100, 100, 1000);
      // cxt.fillStyle = "#fc1";
      // cxt.fill();
      cxt.drawImage(sprite.pic_path, sprite.left, sprite.top, sprite.width, sprite.height);
      // cxt.draw();
    }
    // doDraw()

    const doDraw2 = (dpic)=>{
      let pic_ = cxt.createPattern(dpic, "no-repeat");
      Draw.drawUsingArc(rect, radius, cxt);
      cxt.fillStyle = pic_;
      cxt.fill();
    };
    Draw.save_return(cxt, () => { doDraw() });
  }
};

// 白色背景绘制器
export const bgPainter = {
  paint: function (sprite, cxt) {
    const rect = Draw.Rect(sprite.left, sprite.top, sprite.width, sprite.height);
    cxt.beginPath();
    Draw.drawUsingArc(rect, radius, cxt);
    cxt.fillStyle = '#fff';
    cxt.fill();
    cxt.restore()
  }
};



